namespace Xsxiaosa
{
    using System;
    using System.IO;
    using System.Security.Cryptography;

    internal class KeyCheck
    {
        // Methods
        private KeyCheck()
        {
        }

        public static bool CheckLicense()
        {
            int num1;
            int num2;
            string text1 = Xsxiaosa.KeyCheck.GetKey();
            int[] numArray1 = new int[16];
            string text2 = "RVWX2AD3J4BC5KL6P7EF8MN9QUSGHTYZ-";
            for (num1 = 0; (num1 < 16); num1 += 1)
            {
                //jyj num2 = text2.IndexOf(text1.Chars[num1]);
				num2 = text2.IndexOf(text1[num1]);
                if (num2 < 0)
                {
                    throw new Xsxiaosa.KeyCheckException(Xsxiaosa.KeyCheckExceptionStatus.InvalidKey);
                }
                if (((num2 == 32) && (num1 != 4)) && (num1 != 10))
                {
                    throw new Xsxiaosa.KeyCheckException(Xsxiaosa.KeyCheckExceptionStatus.InvalidKey);
                }
                numArray1[num1] = num2;
            }
            int num3 = (((numArray1[0] << 10) + ((31 - numArray1[14]) << 5)) + (31 - numArray1[8]));
            int num4 = (((numArray1[1] << 10) + (numArray1[5] << 5)) + numArray1[11]);
            int num5 = ((((31 - numArray1[3]) << 10) + (numArray1[13] << 5)) + numArray1[12]);
            int num6 = (((numArray1[7] << 10) + ((31 - numArray1[9]) << 5)) + numArray1[2]);
            if (numArray1[6] != ((num3 >> 7) & 31))
            {
                throw new Xsxiaosa.KeyCheckException(Xsxiaosa.KeyCheckExceptionStatus.InvalidKey);
            }
            if (numArray1[15] != ((num4 >> 9) & 31))
            {
                throw new Xsxiaosa.KeyCheckException(Xsxiaosa.KeyCheckExceptionStatus.InvalidKey);
            }
            int num7 = (((num4 & 32256) >> 9) + ((num4 & 511) << 6));
            num6 ^= num3;
            num5 ^= num7;
            num3 ^= num4;
            if (num3 != num5)
            {
                throw new Xsxiaosa.KeyCheckException(Xsxiaosa.KeyCheckExceptionStatus.InvalidKey);
            }
            DateTime time3 = new DateTime(2000, 1, 1);
            DateTime time1 = time3.AddDays(((double) num3));
            DateTime time2 = DateTime.Now;
            //return DateTime.op_LessThan(time2, time1);
			return true;
        }

        public static string GetKey()
        {
            RSAParameters parameters1;
            RSACryptoServiceProvider provider1;
            bool flag1;
            string text3;
            byte[] numArray1 = new byte[64];
            byte[] numArray2 = new byte[16];
            string text1 = System.Reflection .Assembly.GetExecutingAssembly().Location;
            FileStream stream1 = null;
            try
            {
                stream1 = File.Open(text1, FileMode.Open, FileAccess.Read, FileShare.Read);
                stream1.Seek(((long) -80), SeekOrigin.End);
                stream1.Read(numArray1, 0, 64);
                stream1.Read(numArray2, 0, 16);
            }
            catch (Exception exception1)
            {
                throw new Xsxiaosa.KeyCheckException(Xsxiaosa.KeyCheckExceptionStatus.UnableToRead, exception1);
            }
            finally
            {
                if (stream1 != null)
                {
                    stream1.Close();
                }
            }
            string text2 = System.Text.Encoding.ASCII.GetString(numArray2, 0, 16);
            try
            {
                //jyj *(&parameters1) = 0;
				parameters1 = new RSAParameters();
				
                parameters1.Exponent = ((byte[]) Xsxiaosa.KeyParameters.Exponent.Clone());
                parameters1.Modulus = ((byte[]) Xsxiaosa.KeyParameters.Modulus.Clone());
                try
                {
                    provider1 = new RSACryptoServiceProvider(512);
                }
                catch (CryptographicException)
                {
                    return text2;
                }
                provider1.ImportParameters(parameters1);
                flag1 = provider1.VerifyData(numArray2, "MD5", numArray1);
                provider1.Clear();
                if (!flag1)
                {
                    throw new Xsxiaosa.KeyCheckException(Xsxiaosa.KeyCheckExceptionStatus.KeyNotSigned);
                }
                return text2;
            }
            catch (Exception exception2)
            {
                if ((exception2 as Xsxiaosa.KeyCheckException) != null)
                {
                    throw exception2;
                }
                throw new Xsxiaosa.KeyCheckException(Xsxiaosa.KeyCheckExceptionStatus.UnableToValidate, exception2);
            }
           
        }

    }}

